<?php
/*------------------------------------------
* @AUTHOR: TANDAT @EMAIL:tidusvn05@gmail.com
* @PHONE: +84933731173
* -----------------------------------------*/
class D_Validate {
	protected $_properties;
	protected $_messages;
	
	const email_msg = "email not valid";
	const phone_msg = "phone number is not valid";
	const required_msg = " をご入力ください。";
	//------PROPERTY KEY----
	const username = "username";
	const company_name = "company_name";
	const company_name_kana = "company_name_kana";
	const zip_code = "zip_code";
	const state = "state";
	const city = "city";
	const capital = "capital";
	const business = "business";
	const area = "area";
	const place = "place";
	const business_area = "business_area";
	const business_area_text = "business_area_text";
	const tel = "tel";
	const internet_shop_contact_number = "internet_shop_contact_number";
	const lastname = "lastname";
	const firstname = "firstname";
	const lastname_kana = "lastname_kana";
	const firstname_kana = "firstname_kana";
	const email = "email";
	const email_retype = "email_retype";
	const password = "password";
	const password_retype = "password_retype";
	const nick_name = "nick_name";
	const division = "division";
	const division_text = "division_text";
	const position = "position";
	const position_text = "position_text";
	const subject = "subject";
	const content = "content";
	const representative_name = "representative_name";
	const delete_comment = "delete_comment";
	const publish_comment = "delete_comment";		
			
	const service_name = "service_name";
	const catch_copy = "catch_copy";	
	const target_area = "target_area";
	const scale_employee = "scale_employee";
	const recommend1 = "recommend1";
	const service_content = "service_content";
	const price = "price";
	const price_explain = "price_explain";
	const main_category = "main_category";
	
	//--- INQUIRY-----
	const inquiry_type = "inquiry_type";
	const inquiry_content = "inquiry_content";
	//----TMPPWd---
	const tmp_pwd = "tmp_pwd";
	const new_pwd = "new_pwd";
	const new_pwd_confirm = "new_pwd_confirm";
	//----- user setting ---
	const u07_001 = "u07_001";
	
	const len_30 = "len_30";
	
	//------MESSAGE KEY = ERROR TYPE -----
	const required = "required";
	const less = "less";//it hon length
	const between = "between";
	const message_zip_code = "zip_code";
	const no_select = "no_select";
	const message_city = "city";
	const message_001 = "message_001";  //please input with 12 char
	const over_figures = "over_figures";
	const message_002 = "message_002"; //between 
	const message_003 = "message_003";//please input with 12 char kana
	const message_004 = "message_004";
	const message_005 = "message_005";//to do not match
	const message_006 = "message_006"; // password 
	const message_007 = "message_007"; // nick name
	const message_008 = "message_008";
	const message_009 = "message_009";
	const tmp_incorrect = "tmp_incorrect";
	
	//------ INDENT -------
	const indent_value = "value";
	const indent_value1 = "value1";
	const indent_value2 = "value2";
	const indent_len = "len";
	const indent_min = "min";
	const indent_max = "max";
	
	function __construct(){
		$this->_properties =  new Zend_Config_Ini ( './application/configs/validate.ini', 'properties' );
		$this->_messages =  new Zend_Config_Ini ( './application/configs/validate.ini', 'messages' );
	}
	
	static function email($email) {
		return Zend_validate::is($email,"EmailAddress");
	}
	static function is_number($num){
		return preg_match ( "/^[0-9]+$/", $num );
	}
	
	
	static function username($username){
		return preg_match ( "/^[a-zA-Z0-9_.]{4,20}$/", $username );
	}
	
	static function password($password) {
		return preg_match ( "/^[a-zA-Z0-9_.\,\#\%\@\-\+\*]{4,40}$/", $password );
	}
	
	
	static function tel($tel){
		return preg_match ( "/^[0-9_.]{10,11}$/", $tel );
	}
	static function phone($tel){
		return preg_match ( "/^[0-9_.]{10,11}$/", $tel );
	}
	
	function required($field, $property){
		return self::validate_required($field, $property);
	}
	
	function validate_required($field, $property){
		$errors = array();
		if ( $field=='' ){
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => self::get_property($property)));
			$errors[] = $message;
		}
		return $errors;
	}
	
	function validate_over_figures($field, $property,$len){
		$errors = array();
		if ( $field!='' && D_Utf8::len($field) > $len){
			$message = self::parse(D_Validate::over_figures, array(D_Validate::indent_value => self::get_property($property),D_Validate::indent_len => $len ));
			$errors[] = $message;
		}
		return $errors;
	}
	function validate_over_figures2($field, $property, $len){
		$errors = array();
		if ( $field!='' && D_Utf8::len($field) > $len){
			$message = self::parse("over_figures2", array(D_Validate::indent_value => self::get_property($property),D_Validate::indent_len => $len ));
			$errors[] = $message;
		}
		return $errors;
	}
	
	
	
	//---------------------------------------
	//
	//-------------------------------------
	
	function validate_username($field){
		
	}
	function validate_email($field){
		$errors = array();
		$property1 = self::get_property(D_Validate::email);
		$len = 100;
		if (trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property1));
		}elseif (!D_Validate::email($field) || D_Utf8::len($field) > $len) {
			$errors[] = self::parse(D_Validate::message_004, array(D_Validate::indent_value => $property1, D_Validate::indent_len => $len));;
		}elseif (D_Validate::is_mobile_email($field)) {
			$errors[] = self::parse(D_Validate::message_009, array(D_Validate::indent_value => $property1));;
		}
		return $errors;
	}
	
	function validate_password($field,$key=null){
		$errors = array();
		if(null != $key){
			$property1 = self::get_property($key);
		}else{
			$property1 = self::get_property(D_Validate::password);
		}
		$property2 = self::get_property(D_Validate::password_retype);
		
		$min = 8;
		$max = 20;
		if (trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property1));
		}elseif (!D_Validate::is_1byte_text($field) || D_Utf8::len($field) > $max ||  D_Utf8::len($field) < $min) {
			$errors[] = self::parse(D_Validate::message_006, array(D_Validate::indent_value => $property1, D_Validate::indent_min => $min, D_Validate::indent_max => $max));
		}
		return $errors;
	}
	
	function validate_company_name($field){
		return self::required_and_less($field, D_Validate::company_name,30);
	}
	function validate_company_name_kana($field){
		$errors = array();
		//$property= self::get_property(D_Validate::company_name_kana);
		$property = self::get_property(D_Validate::company_name_kana);
		if (trim($field)==''){
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}else if(D_Utf8::len(trim($field)) > 25||! D_Validate::is_2byte_kana($field)){
			//echo self::get_property("company_name");
			$message = self::parse(D_Validate::message_003, array(D_Validate::indent_value => $property, D_Validate::indent_len => 25));
			$errors[] = $message;
		}
		
		return $errors;
	}
	
	function validate_zip_code($field){
		$errors = array();
		$property = self::get_property(D_Validate::zip_code);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::is_number($field)|| D_Utf8::len(trim($field))!=7){
			$errors[] = self::parse(D_Validate::message_zip_code, array(D_Validate::indent_value => $property));
		}
		return $errors;
	}
	
	function validate_zip_code_not_required($field){
		$errors = array();
		$property = self::get_property(D_Validate::zip_code);
		if(trim($field)!=''){
			if(!D_Validate::is_number($field)|| D_Utf8::len(trim($field))!=7){
				$errors[] = self::parse(D_Validate::message_zip_code, array(D_Validate::indent_value => $property));
			}
		}
		return $errors;
	}
	
	function validate_state($field){
			return self::no_select($field, D_Validate::state);
	}

	function validate_city($field){
		$errors = array();
		$property = self::get_property(D_Validate::city);
		$len = 30;
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
		}
		return $errors;
	}
	
	function validate_city_not_required($field){
		$errors = array();
		$property = self::get_property(D_Validate::city);
		$len=30;
		if(trim($field)!=''){
			if(/*!D_Validate::full_width_text($field) ||*/ D_Utf8::len(trim($field))>$len){
				$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
			}
		}
		return $errors;
	}
	
	function validate_capital($field){
		$errors = array();
		$property = self::get_property(D_Validate::capital);
		$len = 13;
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(/*!D_Validate::full_width_text($field) ||*/ D_Utf8::len(trim($field))>$len){
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
		}
		
		return $errors;
	}
			
	function validate_representative_name($field){
		$errors = array();
		$property = self::get_property(D_Validate::representative_name);
		$len = 25;
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
		}
		
		return $errors;
	}
	
	function validate_representative_name_not_required($field){
		$errors = array();
		$property = self::get_property(D_Validate::representative_name);
		$len=25;
		if(trim($field)!=''){
			if(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
				$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
			}
		}
		return $errors;
	}
		
	function validate_business($field){
		$errors = array();
		$property = self::get_property(D_Validate::business);
		
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}
		return $errors;
	}
	
	function validate_area($field){
		$errors = array();
		$property = self::get_property(D_Validate::area);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>30){
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => 30));
		}
		return $errors;
	}
	
	function validate_area_not_required($field){
		$errors = array();
		$property = self::get_property(D_Validate::area);
		if(trim($field)!=''){
			if(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>30){
				$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => 30));
			}
		}
		return $errors;
	}
	
		function validate_place($field){
			return self::over_figures($field, D_Validate::place,30);
		}
	
	function validate_business_area($field){
		return self::no_select($field, D_Validate::business_area);
	}
	
		function validate_business_area_text($field_required,$field){
			if($field_required=='999'){
				return self::required_and_less($field, D_Validate::business_area_text,20);
			}else{
				return array();
			}
		}

	function validate_tel($field){
		return self::required_not_number_or_not_between_figures($field, D_Validate::tel);
	}
	function validate_internet_shop_contact_number($field){
		$errors = array();
		$property = self::get_property(D_Validate::internet_shop_contact_number);
		if(trim($field)=='') return $errors;
		
		if(!D_Validate::is_number($field) || !(D_Utf8::len(trim($field)) == 8 || D_Utf8::len(trim($field)) == 11)){
			$errors[] = self::parse(D_Validate::message_002, array(D_Validate::indent_value => $property,D_Validate::indent_min => 8, D_Validate::indent_max => 11));
		}
		
		return $errors;
	}
	
	function validate_lastname($field){
		$errors = array();
		$property = self::get_property(D_Validate::lastname);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field)) > 12){
			
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => 12));
		}
		return $errors;
	}
	function validate_firstname($field){
		$errors = array();
		$property = self::get_property(D_Validate::firstname);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))> 12){
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => 12));
		}
		return $errors;
	}
	function validate_lastname_kana($field){
		$errors = array();
		$property = self::get_property(D_Validate::lastname_kana);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::is_2byte_kana($field) || D_Utf8::len(trim($field))> 24){
			$errors[] = self::parse(D_Validate::message_003, array(D_Validate::indent_value => $property,D_Validate::indent_len => 24));
		}
		return $errors;
	}
	function validate_firstname_kana($field){
		$errors = array();
		$property = self::get_property(D_Validate::firstname_kana);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::is_2byte_kana($field) || D_Utf8::len(trim($field))> 24){
			$errors[] = self::parse(D_Validate::message_003, array(D_Validate::indent_value => $property,D_Validate::indent_len => 24));
		}
		return $errors;
	}
	
	function validate_email_and_retype_email($field1,$field2){
		$errors = array();
		$property1 = self::get_property(D_Validate::email);
		$property2 = self::get_property(D_Validate::email_retype);
		$len = 100;
		if (trim($field1)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property1));
		}elseif (!D_Validate::email($field1) || D_Utf8::len($field1) > $len) {
			$errors[] = self::parse(D_Validate::message_004, array(D_Validate::indent_value => $property1, D_Validate::indent_len => $len));;
		}elseif (D_Validate::is_mobile_email($field1)) {
			$errors[] = self::parse(D_Validate::message_009, array(D_Validate::indent_value => $property1));;
		}
		
		if (trim($field2)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property2));
		}elseif (!D_Validate::email($field2) || D_Utf8::len($field2) > $len) {
			$errors[] = self::parse(D_Validate::message_004, array(D_Validate::indent_value => $property2, D_Validate::indent_len => $len));;
		}elseif (D_Validate::is_mobile_email($field2)) {
			$errors[] = self::parse(D_Validate::message_009, array(D_Validate::indent_value => $property2));;
		}
		
		if ($field1 != $field2) {
			$errors[] = self::parse(D_Validate::message_005, array(D_Validate::indent_value1 => $property1, D_Validate::indent_value2 => $property2));;
		}
		return $errors;
	}
	
	function validate_password_and_password_retype($field1,$field2,$key1 = null,$key2 = null){
		$errors = array();
		if($key1== null)
			$key1 =D_Validate::password;
		if($key2== null)
			$key2 =D_Validate::password_retype;	
			
		$property1 = self::get_property($key1);
		$property2 = self::get_property($key2);
		$min = 8;
		$max = 20;
		if (trim($field1)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property1));
		}elseif (!D_Validate::is_1byte_text($field1) || D_Utf8::len($field1) > $max ||  D_Utf8::len($field1) < $min) {
			$errors[] = self::parse(D_Validate::message_006, array(D_Validate::indent_value => $property1, D_Validate::indent_min => $min, D_Validate::indent_max => $max));
		}
		
		if (trim($field2)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property2));
		}elseif (!D_Validate::is_1byte_text($field2) || D_Utf8::len($field2) > $max ||  D_Utf8::len($field2) < $min) {
			$errors[] = self::parse(D_Validate::message_006, array(D_Validate::indent_value => $property2, D_Validate::indent_min => $min, D_Validate::indent_max => $max));;
		}
		
		if ($field1 != $field2) {
			$errors[] = self::parse(D_Validate::message_005, array(D_Validate::indent_value1 => $property1, D_Validate::indent_value2 => $property2));;
		}
		return $errors;
	}
	
	function validate_nick_name($field){
		$errors = array();
		$property = self::get_property(D_Validate::nick_name);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::is_nick_name($field) || D_Utf8::len(trim($field))> 20){
			$errors[] = self::parse(D_Validate::message_007, array(D_Validate::indent_value => $property,D_Validate::indent_len => 20));
		}
		return $errors;
	}
	
	function validate_division($field){
		return self::no_select($field, D_Validate::division);
	}
	function validate_division_text($field){
		return self::required_and_less($field, D_Validate::division_text,20);
	}
	function validate_position($field){
		return self::no_select($field, D_Validate::position);
	}
	
	function validate_position_text($field, $required=true){
		if($required){
			return self::required_and_less($field, D_Validate::position_text,20);
		}else{
			return self::over_figures($field, D_Validate::position_text,20);
		}
	}
	
	function validate_subject($subject){
		return self::required_and_less($subject, D_Validate::subject,100);
	}
	
	function validate_content($content){
		return self::required_and_less($content, D_Validate::content,500);
	}
	
	/**
	 * 
	 * 
	 * ASKUL ADMIN
	 */
	
	function validate_admin_member_id($field){
		return self::required_and_between($field,2,20, "admin_id");
	}
	function validate_admin_member_name($field){
		$errors = array();
		$len = 20; 
		$property = self::get_property("admin_name");
		$msg2="message_011";
		if (trim($field)==''){
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}else if(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field)) > $len){
			//echo D_Utf8::len(trim($field));
			$message = self::parse($msg2, array(D_Validate::indent_value => $property, D_Validate::indent_len => $len));
			$errors[] = $message;
		}
		return $errors;
	}
	
	/*------------------
	 * 
	 * 
	 */
	function validate_url_and_over_figures($field,$property,$len){
		$errors = array();
		if($field != ''){
			if(!Zend_Uri::check($field)|| D_Utf8::len($field) > $len){
				$property = self::get_property($property);
				$errors[] = self::parse("message_010", array(D_Validate::indent_value => $property));
			}
		}
		return $errors;
	}
	
	function getError($property_key, $message_key, $indent_array=array()){
		$property = self::get_property($property_key);
		$indent_array = array_merge($indent_array,array(D_Validate::indent_value => $property ));
		$error_msg = self::parse($message_key,$indent_array);
		return $error_msg;
	}
	
	/*------------------------------------------
	* PRIVATE MSG
	* @PHONE: +84933731173
	* -----------------------------------------*/
	function no_select($field,$property){
		$errors = array();
		$property = self::get_property($property);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::no_select, array(D_Validate::indent_value => $property));
		}
		return $errors;
	}
	
	
	//bat buoc va it hon 1 so
	
	
	function required_and_less($field, $property, $len=30){
		$errors = array();
		$property = self::get_property($property);
		if (trim($field)== ''){
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}else if(D_Utf8::len(trim($field)) > $len){
			//echo self::get_property("company_name");
			$message = self::parse(D_Validate::less, array(D_Validate::indent_value => $property, D_Validate::indent_len => $len));
			$errors[] = $message;
		}
		
		return $errors;
	}
	
	function validate_required_and_over_figures($field, $property, $len=30){
		return self::required_and_less($field, $property,$len);
	}
	function validate_required_and_over_figures2($field, $property, $len=30){
		$errors = array();
		$property = self::get_property($property);
		if (trim($field)==''){
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}else if(D_Utf8::len(trim($field)) > $len){
			$message = self::parse("over_figures2", array(D_Validate::indent_value => $property, D_Validate::indent_len => $len));
			$errors[] = $message;
		}
		
		return $errors;
	}
	
	function validate_not_selected($field, $property){
		return self::no_select($field, $property);
	}
	
	function not_2byte_or_not_number_or_over_figures($field, $property, $len=30){
		$errors = array();
		$property = self::get_property($property);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
		}
		return $errors;
	}
	
	function over_figures($field,$property, $len=30){
		$errors = array();
		$property = self::get_property($property);
		if(D_Utf8::len(trim($field))>$len){
			$errors[] = self::parse(D_Validate::over_figures, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
		}
		return $errors;
	}
	
	
	
	/*------------------------------------------
	* PRIVATE MSG
	* @PHONE: +84933731173
	* -----------------------------------------*/
	function not_number_or_not_between_figures($field, $property, $min=10,$max=11){
		$errors = array();
		$property = self::get_property($property);
		if(!D_Validate::is_number($field) || D_Utf8::len(trim($field))>$max || D_Utf8::len(trim($field))< $min){
			$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property));
		}
		return $errors;
	}
	
	function required_not_number_or_not_between_figures($field, $property, $min=10,$max=11){
		$errors = array();
		$property = self::get_property($property);
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}elseif(!D_Validate::is_number($field) || D_Utf8::len(trim($field))>$max || D_Utf8::len(trim($field))< $min){
			$errors[] = self::parse(D_Validate::message_002, array(D_Validate::indent_value => $property,D_Validate::indent_min => $min, D_Validate::indent_max => $max));
		}
		return $errors;
	}
	
	function required_and_between($field, $min=10,$max=11,$property,$msg1='',$msg2=''){
		$errors = array();
		$property = self::get_property($property);
		if(trim($field)==''){
			$msg = $msg1!=''? $msg1:D_Validate::required;
			$errors[] = self::parse($msg, array(D_Validate::indent_value => $property));
		}elseif(D_Utf8::len(trim($field))>$max || D_Utf8::len(trim($field))< $min){
			$msg = $msg2!=''? $msg2:D_Validate::message_002;
			$errors[] = self::parse($msg, array(D_Validate::indent_value => $property,D_Validate::indent_min => $min, D_Validate::indent_max => $max));
		}
		return $errors;
	}
	
	static function validate_required_array($array){
		$errors = array();
		foreach ($array as $property =>  $field){
			if ( trim($field)=='' ){
				$message = self::parse(D_Validate::required, array(D_Validate::indent_value => self::get_message($property)));
				$errors[] = $message;
			}
		}
		return $errors;
	}
	
	static function validate_phone($tel,$field_name){
		$errors = array();
		if (D_Validate::required($tel, $field_name)){
			$errors[] = D_Validate::required($tel, $field_name);
		}elseif (!D_Validate::phone($tel)) {
			$errors[] = D_Validate::phone_msg;
		}
		return $errors;
	}
	
	static function is_mobile_email($email){
		$result = false;
		if(Zend_Validate::is($email, "EmailAddress")){
			$file = './library/mobile_email.txt';
			$txt = file($file);
			foreach ($txt as $line):
				if (strpos($email, trim($line))) {
					return true;
				} 
			endforeach;
		}
		return $result;
	}
	
	static function full_width_text($input){
		/*
		mb_internal_encoding('EUC-JP');
		$sl = strlen($input);
		$jl = mb_strwidth($input);
		if ( ($sl!= $jl && !D_Utf8::is_katakana($input)) || preg_match("/^[0-9\-\s]*$/", $input) ) {
			return true;
		}*/
		$zen = new D_Validate_Zenkaku();
		return $zen->isValid($input);
		//return false;
	}
	static function full_width_kana($input){
		/*$input = trim($input);
		mb_internal_encoding('EUC-JP');
		$sl = strlen($input);
		$jl = mb_strwidth($input);
		if ($sl!= $jl || D_Utf8::is_katakana($input)) {
			return true;
		} */
		$obj = new D_Validate_ZenkakuKana();
		return $obj->isValid($input);
	}
	
	static function half_width_text($input){
		/*mb_internal_encoding('EUC-JP');
		$sl = strlen($input);
		$jl = mb_strwidth($input);
		if ($sl == $jl) {
			return true;
		}*/
		$obj = new D_Validate_Hankaku();
		return $obj->isValid($input);
	}
	
	static function check_2byte($input){
		return true;
	}
	
	function is_2byte_text($input){
		return true;
	}
	
	static function is_2byte_kana($input){
		$va = new D_Validate_ZenkakuKana();
		return $va->isValid($input);
		return D_Utf8::is_katakana($input);
	}
	
	function is_1byte_text($input){
		return true;
	}
	function is_nick_name($input){
		return preg_match("/^[a-zA-Z0-9_]{0,20}$/",$input);
	}
	
	function check_number($input){
		return preg_match ( "/^[0-9_.]+$/", $input );
	}
	
	function is_text_number($input){
		return preg_match("/^[a-zA-Z0-9]+$/",$input);
	}
	
	/*------------------------------------------
	* error type : required,.....
	* vars = array('value' => 'company_name','ident key' => 'property key' )
	* 
	* -----------------------------------------*/
	function parse($error_type,$message_variables,$custom_message=''){
		
		if($custom_message==''){
			$message = $this->_messages->$error_type;
		}else {
			$message = $custom_message;
		}
		
        foreach ($message_variables as $ident => $value) {
            $message = str_replace("%$ident%", $value, $message);
        }
        
		return $message;
	}
	
	
	function get_property($key){
		return $this->_properties->$key;
	}
	
	function get_message($key){
		return $this->_messages->$key;
	}
	
	static function message($key){
		$_messages =  new Zend_Config_Ini ( './application/configs/validate.ini', 'messages' );
		return $_messages->$key;
	}
	
	function validate_service_delete_comment($field){
		$errors = array();
		$property = self::get_property(D_Validate::delete_comment);
		$len=500;
		if(trim($field)!=''){
			if(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
				$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
			}
		}
		else
		{
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}
		return $errors;
	}
	
	function validate_service_publish_comment($field){
		$errors = array();
		$property = self::get_property(D_Validate::publish_comment);
		$len=500;
		if(trim($field)!=''){
			if(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
				$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
			}
		}
		else
		{
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}
		return $errors;
	}
	
	function validate_image($upload, $field, $old, $isMainImage, $imageType){		
		$error = array();
		
		if (!$upload->getFileName($field))
		{
			if (($isMainImage && $old) || !$isMainImage)
				return $error;			
		}
				
		$property = self::get_property($imageType);	
				
		if (!$upload->isValid($field))
		{			
			$description = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			
			if ($isMainImage)
				$error[] = $description . ': ' . "横150px&nbsp;縦110px以上のjpegもしくはgif画像（推奨サイズ&nbsp;&nbsp;横150px 縦110px）、容量500KByte以下<br />サービスを象徴するようなメイン画像をアップロードしてください。";
			else
				$error[] = $description . ': ' . "横170px 縦124px以上のjpegもしくはgif画像（推奨サイズ　横650px 縦474px）<br />サービスの利用イメージや、画面の画像などをアップロードください。";						
		}
		
		return $error;
	}
	
	function validate_service_name($field){
		$errors = array();
		$property = self::get_property(D_Validate::service_name);
		$len=30;
		if(trim($field)!=''){
			if(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
				//$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
				$errors[] = $property . " 【サービス名】を30文字以内でご入力ください。";
			}
		}
		else
		{
			//$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $property . " 【サービス名】をご入力ください。";
		}
		return $errors;
	}
	
	function validate_catch_copy($field){
		$errors = array();
		$property = self::get_property(D_Validate::catch_copy);
		
		if(trim($field)==''){
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
		}
		return $errors;
	}
	
	function validate_target_area($field){
		$errors = array();
		$property = self::get_property(D_Validate::target_area);
		if ($field==null || !isset($field) || count($field) == 0 || (count($field)==1&&$field[0]==''))
			$errors[] = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			
		return $errors;
	}
	
	function validate_scale_employee($field){
		return self::no_select($field, D_Validate::scale_employee);
	}
	
	function validate_recommend1($field){
		$errors = array();
		$property = self::get_property(D_Validate::recommend1);
		$len=30;
		if(trim($field)!=''){
			if(!D_Validate::full_width_text($field) || D_Utf8::len(trim($field))>$len){
				//$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
				$errors[] = $property . " 【注目ポイント1】を30文字以内でご入力ください。";
			}
		}
		else
		{
			//$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $property . " 【注目ポイント1】をご入力ください。";
		}
		return $errors;
	}
	
	function validate_service_content($field){
		$errors = array();
		$property = self::get_property(D_Validate::service_content);
		$len=1000;
		if(trim($field)!=''){
			if(D_Utf8::len(trim($field))>$len){
				//$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
				$errors[] = "【サービス内容】を１000文字以内でご入力ください。	";
			}
		}
		else
		{
			//$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $property . " 【サービス内容】をご入力ください。";
		}
		return $errors;
	}
	
	function validate_price($field){
		$errors = array();
		$property = self::get_property(D_Validate::price);
		$len=30;
		if(trim($field)!=''){
			if(/*!D_Validate::full_width_text($field) || */D_Utf8::len(trim($field))>$len){
				$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
			}
		}
		else
		{
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}
		return $errors;
	}
	
	function validate_price_explain($field){
		$errors = array();
		$property = self::get_property(D_Validate::price_explain);
		$len=500;
		
		if(trim($field)!=''){
			if(/*!D_Validate::full_width_text($field) || */D_Utf8::len(trim($field))>$len){
				$errors[] = self::parse(D_Validate::message_001, array(D_Validate::indent_value => $property,D_Validate::indent_len => $len));
			}
		}
		else
		{
			$message = self::parse(D_Validate::required, array(D_Validate::indent_value => $property));
			$errors[] = $message;
		}
		return $errors;
	}
	
	function validate_main_category($field){
			return self::no_select($field, D_Validate::state);
	}
}

?>